package LeetCode.day1;

/**
 * @description:
 * @author: Cter
 * @date: 2020/6/19
 */
class Solution {
    public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
        String a = getNextValue(l1);
        String b = getNextValue(l2);
        long c = Long.parseLong(new StringBuilder(a).reverse().toString())+Long.parseLong(new StringBuilder(b).reverse().toString());
        System.out.println(c);
        String cstr = String.valueOf(c);
        char[] chars = cstr.toCharArray();
        ListNode temp = null;
        for (int i = 0; i < chars.length ; i++){
            String cc= String.valueOf(chars[i]);
            ListNode listNode = new ListNode(Integer.parseInt(cc));
            if (temp!=null){
                listNode.next = temp;
            }
            temp = listNode;
        }
        System.out.println(getNextValue(temp));
        return temp;
    }

    public  String getNextValue(ListNode node){
        if (node==null){
            return "";
        }
        return node.val+getNextValue(node.next);
    }

}
